<?php

/**

$serv = new swoole_server("127.0.0.1", 9501);
$serv->on('connect', function ($serv, $fd){
    echo "Client:Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $serv->send($fd, 'Swoole: '.$data);
    $serv->close($fd);
});
$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});

$serv->start();
*/


$host = "0.0.0.0"; //监听的ip地址
$port = "9501"; // 监听的端口
$serv = new swoole_server($host,$port);

//$swoole_server->on(string $event,mixed $callback);
/**
 * $event
 * connect :当建立链接的时候($serv:服务器信心，$fd:客户端信息) 
 * receive：当接受到数据时（$serv:服务器信心，$fd:客户端信息,$form_id:id,$data:数据）;
 * close:关闭链接时
 */
 
 
//connect :当建立链接的时候($serv:服务器信心，$fd:客户端信息) 
$serv->on("connect",function($serv,$fd){
    echo "connect.\n";
});

//receive：当接受到数据时（$serv:服务器信心，$fd:客户端信息,$form_id:id,$data:数据）;
$serv->on("receive",function($serv,$fd,$from_id,$data){
    echo "receive.\n";
});
// close:关闭链接时
$serv->on("close",function($serv,$fd){
    echo "close.\n";
});

$serv->start();

// ps -ajft 查看进程 

?>